ListNode* deleteNode(ListNode* head, int val) {
    if(head->val == val) return head->next;

    ListNode *pre = head, *cur = head->next;
    while(cur && cur->val != val)
    {
        pre = cur;
        cur = cur->next;
    }
    if(cur) pre->next = cur->next;
    
    return head;
}